home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / USBModem / ModemStub.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-25  |  8.5 KB  |  304 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ModemStub.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                xxx put dri here xxx
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            xxx put technology here xxx
  17.  
  18. */
  19.  
  20. #include <Errors.h>
  21.  
  22. #include "Modem.h"
  23. #include "ModemStub.h"
  24. #include "ModemDriver.h"
  25. #include "ShimSerialStub.h"
  26. #include "ShimSerialHAL.h"
  27. #include "ModemVersion.h"
  28.  
  29. //------------------------------------------------------
  30. //
  31. // Globals
  32. //
  33. //------------------------------------------------------
  34.  
  35. ShimSerialGlobals*    gGlobals;
  36.  
  37. //------------------------------------------------------
  38. //
  39. //    This is the driver description structure that the expert looks for first.
  40. //  If it's here, the information within is used to match the driver
  41. //  to the device whose descriptor was passed to the expert.
  42. //    Information in this block is also used by the expert when an
  43. //  entry is created in the Name Registry.
  44. //
  45. //------------------------------------------------------
  46.  
  47. USBDriverDescription    TheUSBDriverDescription = 
  48. {
  49.     // Signature info
  50.     kTheUSBDriverDescriptionSignature,
  51.     kInitialUSBDriverDescriptor,
  52.     
  53.     // Device Info
  54.     kUSBVendor,                             // vendor ID
  55.     kUSBProduct,                            // product ID
  56.     0,                                        // version of product = not device specific
  57.     0,                                        // protocol = not device specific
  58.     
  59.     // Interface Info            
  60.     0,                                        // Configuration Value (doesn't matter)
  61.     0,                                        // Interface Number
  62.     kUSBCommClass,                            // Interface Class
  63.     2,                                         // Interface SubClass (Abstract Control Model)
  64.     1,                                        // Interface Protocol (V.25ter)    
  65.     
  66.     // Driver Info
  67.     kModemName,                                // Driver name for Name Registry
  68.     kUSBCommClass,                            // Device Class
  69.     0,                                        // Device Subclass 
  70.     kVMajor,                                 // version of driver (see ModemVersion.h)
  71.     kVMinor, 
  72.     kVStage, 
  73.     kVRelease,
  74.     
  75.     // Driver Loading Info
  76. //    kUSBDoNotMatchGenericDevice                // Flags
  77.     0
  78. };
  79.     
  80. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  81. {
  82.     kClassDriverPluginVersion,                // Version of this structure
  83.     modemDriverValidateHW,                    // Hardware Validation Procedure
  84.     modemDriverInitialize,                    // Initialization Procedure
  85.     modemDriverInitInterface,                // Interface Initialization Procedure
  86.     modemDriverFinalize,                    // Finalization Procedure
  87.     modemDriverNotifyProc,
  88. };
  89.  
  90. CFragConnectionID    ConnID;                    // Need to remember this
  91.  
  92. /***********************************************************************************/
  93. //    Function:        modemDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
  94. //    Description:    Called upon load by Expert
  95. //
  96. //    Input:            Device reference, Device descriptor
  97. //    Output:            noErr
  98. /***********************************************************************************/
  99.  
  100. static OSStatus modemDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
  101. {
  102. #pragma unused (device, desc)
  103.  
  104.     TraceMessage(0,kCRMName"- Entering modemDriverValidateHW");
  105.         
  106.     return noErr;
  107. }
  108.  
  109. /***********************************************************************************/
  110. //    Function:        OSStatus modemDriverInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc,
  111. //                                                                         UInt32 busPowerAvailable)
  112. //    Description:    Called upon load by Expert
  113. //
  114. //    Input:            Device reference, Device descriptor, bus power available
  115. //    Output:            result
  116. /***********************************************************************************/
  117.  
  118. static OSStatus modemDriverInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable)
  119. {
  120. #pragma unused (busPowerAvailable)
  121.     
  122. OSStatus err;
  123.  
  124.     TraceMessage(0,kCRMName"- Entering modemDriverInitialize");
  125.  
  126.     gGlobals = (ShimSerialGlobals*)PoolAllocateResident(sizeof(ShimSerialGlobals),true);
  127.     if (gGlobals == NULL)
  128.         goto bail;
  129.     
  130.     USBExpertStatus(0, kCRMName"- Modem driver loading as Class - "kVers2Long Bugon, 0);
  131.     
  132.     err = modemDriverEntry(device, pDesc);
  133.  
  134.     if (err != noErr)
  135.     {
  136.         StatusMessage(0, kCRMName"- Configuration failed", err);
  137.         goto bail;
  138.     } else {
  139.         //    Install Device Control Entry for both the ".In" and ".Out functions that are
  140.         //    requied for a serial driver which is what we are.
  141.         if (noErr != InstallShimDrvr(ConnID))
  142.         {
  143.             StatusMessage(0, kCRMName" - Can't install DCEs!", 0);
  144.             goto bail;
  145.         }
  146.     }
  147.  
  148.     return noErr;
  149.  
  150. bail:
  151.     if (gGlobals)
  152.         PoolDeallocate(gGlobals);
  153.     gGlobals = NULL;
  154.     
  155.     return openErr;
  156. }
  157.  
  158. /***********************************************************************************/
  159. //    Function:        modemDriverInitInterface(UInt32 interfaceNum, USBInterfaceDescriptor *interfaceDesc, 
  160. //                                                    USBDeviceDescriptor    *deviceDesc, USBDeviceRef device)
  161. //    Description:    Called to initialize driver for an individual interface - 
  162. //                    either by expert or internally by driver
  163. //
  164. //    Input:            Interface number, Interface descriptor, Device Descriptor, Device Reference
  165. //    Output:            result
  166. /***********************************************************************************/
  167.  
  168. static OSStatus modemDriverInitInterface(UInt32 interfaceNum, USBInterfaceDescriptor *interfaceDesc, USBDeviceDescriptor *deviceDesc, USBDeviceRef device)
  169. {
  170. #pragma unused (interfaceNum, interfaceDesc)
  171.  
  172. OSStatus err;
  173.  
  174.     TraceMessage(0,kCRMName"- Entering modemDriverInitInterface");
  175.  
  176.     if (gGlobals == NULL)
  177.         gGlobals = (ShimSerialGlobals*)PoolAllocateResident(sizeof(ShimSerialGlobals),true);
  178.  
  179.     if (gGlobals == NULL)
  180.         goto bail;
  181.  
  182.     USBExpertStatus(0, kCRMName"- Modem driver loading as Interface "kVers2Long Bugon, 0);
  183.     
  184.     err = modemDriverEntry(device, deviceDesc);
  185.  
  186.     if (err != noErr)
  187.     {
  188.         StatusMessage(0, kCRMName"- Configuration failed", err);
  189.         goto bail;
  190.     } else {
  191.         //    Install Device Control Entry for both the ".In" and ".Out functions that are
  192.         //    requied for a serial driver which is what we are.
  193.         if (noErr != InstallShimDrvr(ConnID))
  194.         {
  195.             StatusMessage(0, kCRMName"- Can't install DCEs!", 0);
  196.             goto bail;
  197.         }
  198.     }
  199.         
  200.     return noErr;
  201.  
  202. bail:
  203.     if (gGlobals)
  204.         PoolDeallocate(gGlobals);
  205.     gGlobals = NULL;
  206.     
  207.     return openErr;
  208. }
  209.  
  210. /***********************************************************************************/
  211. //    Function:        modemDriverFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc)
  212. //    Description:    Called by Expert when driver is being shut down
  213. //
  214. //    Input:            Device reference, Device descriptor
  215. //    Output:            noErr
  216. /***********************************************************************************/
  217.  
  218. static OSStatus modemDriverFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc)
  219. {
  220. #pragma unused (device, pDesc)
  221.  
  222.     TraceMessage(0,kCRMName"- Entering modemDriverFinalize");
  223.     
  224.     if (gGlobals)
  225.     {
  226.         /* This is done here just as a safeguard because it should have been done in the notify proc */    
  227. //        KillUSBIO();
  228.         ResetDevice();
  229.         RemoveShimDrvr(true);                            // force close - let the shim handle it
  230.         PoolDeallocate(gGlobals);
  231.         gGlobals = NULL;
  232.     }
  233.     
  234.     return noErr;
  235. }
  236.  
  237. /***********************************************************************************/
  238. //    Function:        ExpertEntryProc(ExpertNotificationProcPtr pExpertNotify)
  239. //    Description:    
  240. //
  241. //    Input:            Notification proc pointer
  242. //    Output:            noErr
  243. /***********************************************************************************/
  244.  
  245. static OSStatus ExpertEntryProc(ExpertNotificationProcPtr pExpertNotify)
  246. {
  247. #pragma unused (pExpertNotify)
  248.  
  249.     TraceMessage(0,kCRMName"- Entering ExpertEntryProc");
  250.  
  251.     return noErr;
  252. }
  253.  
  254. /***********************************************************************************/
  255. //    Function:        modemDriverNotifyProc(UInt32 notification, void *pointer)
  256. //    Description:    
  257. //
  258. //    Input:            Notification and pointer
  259. //    Output:            result
  260. /***********************************************************************************/
  261.  
  262. static OSStatus    modemDriverNotifyProc(UInt32 notification, void *pointer, UInt32 refcon)
  263. {
  264. #pragma unused (pointer, refcon)
  265.     
  266.     TraceMessage(0,kCRMName"- Entering modemDriverNotifyProc");
  267.     StatusMessage(0, kCRMName"- Driver Notification = ", notification);
  268.     
  269.     if (notification == kNotifyRemoveDevice)
  270.     {
  271.         if (gGlobals->ShimRef != kInvalidRef)
  272.         {
  273.             KillUSBIO();
  274.             RemoveShimDrvr(true);                            // force close - let the shim handle it
  275.  
  276.             if (gGlobals)
  277.             {
  278.                 PoolDeallocate(gGlobals);
  279.                 gGlobals = NULL;
  280.             } 
  281.         }
  282.     }
  283.     
  284.     return noErr;
  285. }
  286.  
  287. /***********************************************************************************/
  288. //    Function:        InitDriver(CFragInitBlock *init)
  289. //    Description:    This routine saves our connection id
  290. //
  291. //    Input:            init (unused)
  292. //    Output:            noErr
  293. /***********************************************************************************/
  294.  
  295. OSErr InitDriver(CFragInitBlock *init)
  296. {
  297.     OSErr    err = noErr;
  298.     
  299.     TraceMessage(0, kCRMName"- Entering initDriver");
  300.     
  301.     ConnID = init->connectionID;
  302.  
  303.     return err;
  304. }